<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .ptxt{
            border: 1px solid red;
            width: 300px;
            height: 30px;
            line-height: 30px;
        }
    </style>
</head>

<body>
    <input type="text" name="" id="text">
    <p class="ptxt"></p>
    <script>
        var obj = Object.defineProperties({},{
            txt:{
                get:function(){
                    return this.val;
                },
                set:function(v){
                    // 数据劫持
                    oP.innerHTML = v;
                    this.val = v;
                }
            }
        });

        // console.log(obj.txt);
        var oP = document.querySelector('.ptxt');
        var oInp = document.querySelector('#text');

        // oP.innerHTML = obj.txt;

        // 修改obj的txt
        // obj.txt = '123';

        // 用户输入 input时 改变 obj的text
        oInp.onkeyup = function(){
            obj.txt = this.value;
        }

        // console.log(obj.txt);

       

        
    </script>
</body>

</html>